/**
 * kl yy-ds @2021
 */
package com.cxps.server.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * TODO(类描述)
 *
 * @author YouCai.Liu
 * @since 2021/11/29
 * ...
 */
public class ContextStrategy {

    // 定义一个算法族，将算法策略封装
    static Map<String, AbstractStrategy> strategyMap = new HashMap<>();

    static {
        strategyMap.put("V1", new V1AbstractStrategy());
        strategyMap.put("V2", new V2AbstractStrategy());
        strategyMap.put("V3", new V3AbstractStrategy());
    }

    /**
     * 计算价格
     *
     * @param vipLevel
     * @param price
     * @return
     */
    public double getPrice(String vipLevel, double price) {
        if (strategyMap.containsKey(vipLevel)) {
            AbstractStrategy abstractStrategy = strategyMap.get(vipLevel);
            return abstractStrategy.algorithm(price);
        }
        return price;
    }
}
